#-*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui, uic
from PyQt4.Qt import *
import os
import time

TXT = ['','']

qtCreatorFile = "D:\\QTQT\\qttest\\1.ui" # Enter file here.
 
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
 
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
	
	def __init__(self):
		self.e = 'z'
		QtGui.QMainWindow.__init__(self)
		Ui_MainWindow.__init__(self)
		self.setupUi(self)
		self.button1.clicked.connect(self.CalculateTax)
		self.button2.clicked.connect(self.empty)
		self.changebutton.clicked.connect(self.CBbbb)
	def CalculateTax(self,data):
		#获取label的标题.text()
		#修改输入框内容.setText
		#txt = str(self.label.text())
		#self.text2.setText(data)
		TXT[0] = str(self.text1.toPlainText())
		self.text2.setText(' is now being prepared.')		
		#获取输入框内容.toPlainText()
		#修改label标题setText()
		#txt = str(self.text1.toPlainText())
		#adb_text = ''.join(os.popen('%s'%(txt)).readlines())
		#self.text2.setText(self.e + '\n' + adb_text )

	def text_nub(self,data):
		self.text2.setText(data)

	def teb_text(self,data):
		self.label.setText(data)
	
	def empty(self):
		TXT[0] = ''
		self.text2.setText('null')
	def CBbbb(self):
		TXT[1] = 1
 
class Backend(QThread):
	update_date = pyqtSignal(QString)
	def run(self):
		while 1>0:
			if TXT[0] == '':
				time.sleep(1)
			else:
				aa = ''.join(os.popen('%s'%(TXT[0])).readlines())
				data = aa
				if TXT[0] != '':
					self.update_date.emit(QString(str(data)))
class changebutton_(QThread):
	update_date = pyqtSignal(QString)
	def run(self):					
		a = 0
		while 1>0:
			if TXT[1] == '':
				time.sleep(1)
			else:
				a = a+1
				data = a
				self.update_date.emit(QString(str(data)))
				time.sleep(1)

if __name__ == "__main__":

	#https://segmentfault.com/q/1010000005331085
	#多线程UI
	app = QtGui.QApplication(sys.argv)
	window = MyApp()
	
	b = Backend()
	b.update_date.connect(window.text_nub)
	b.start()

	cb = changebutton_()
	cb.update_date.connect(window.teb_text)
	cb.start()

	window.show()
	sys.exit(app.exec_())